//
// Created by 11510 on 2024/6/21.
//
#include <iostream>
#include <string>
#include <memory>
#include <vector>
using namespace std;

void test0() {
    unique_ptr<int> up(new int(8));
//    unique_ptr<int> up2(up);  error

    unique_ptr<int> up3(new int(3));
//    up3 = up; error

    int* p = new int(1);
    unique_ptr<int> up4(p);
    cout << *up4 << endl;
    cout << *p << endl;
}
class Point{
public:
    Point(int x, int y):x(x), y(y){
    }
    void print()const{
        printf("(%d, %d)\n", x, y);
    }
private:
    int x;
    int y;
};
void test1(){
    vector<unique_ptr<Point>> list;
    list.push_back(unique_ptr<Point>(new Point(0, 0)));

    unique_ptr<Point> up(new Point(1, 2));
    list.push_back(move(up));

    list[0]->print();
    list[1]->print();
//    WARN!!! up原本的资源管理权交给了vector，up失去了管理权，此处有段错误
    (*up).print();
}

int main() {
    test1();
    return 0;
}